package org.example.exts;

import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.HandlerCollection;

public class DefaultHandler
{
    public static void main( String[] args ) throws Exception
    {
        final Server server = new Server(8080);
        
        /**
         * handlerCollection 为Hander的集合。
         * 用来管理Handler内部使用addHandler/removeHanlder对hander进行添加和删除
         * 
         */
        
        HandlerCollection childCollection = new HandlerCollection() ;
        childCollection.setHandlers( new Handler[]{ new MyHandler("A"), new MyHandler("B") });
        
        HandlerCollection parentCollection = new HandlerCollection() ;
        parentCollection.setHandlers( new Handler[]{childCollection} );
        
        System.err.println( "parentCollection handlers size is " +parentCollection.getHandlers().length );
        System.err.println( "parentCollection childHandlers size is " +parentCollection.getChildHandlers().length );
        server.setHandler( childCollection );
 
        server.start();
        server.join();
    }
    
}
